import { TFile, Plugin, FrontMatterCache } from 'obsidian';

export default class Util {

    private static _plugin: Plugin;

    static init(plugin: Plugin) { this._plugin = plugin; }

    static containYAMLTag(file: TFile, tag: string): boolean {
        let frontmatter = this._plugin.app.metadataCache.getFileCache(file)?.frontmatter as FrontMatterCache;
        if (!frontmatter) return false;
        let tags: string[] = frontmatter['tags'];
        if (!tags) return false;

        return tags.contains(tag);
    }

    static haveActiveFile(): boolean { return this._plugin.app.workspace.getActiveFile() != null; }

}
